<?php
/**
* Provides access to inline front-end elements.
*
* Copyright (c) 2009 James Gauld <james@jamesgauld.net>
* This file is part of Scribble.
* @license http://www.scribblecms.co.uk/license.txt
*
* @package Scribble
*/
use Buan\Config;
use Buan\Model;
class InlineController extends ScribblePublicController {

	/**
	* Deliver Javascript for the inline UI elements.
	*
	* We get the javascript via this controller action rather than referencing the
	* javascript source file directly because this method ensures that Buan and
	* Scribble are initialized so we can access the Models, config settings, etc.
	*
	* @return void
	*/
	public function js() {

		// Content type
		header("Content-Type: text/javascript");
		
		// Load the page and version
		$page = Model::create('Page');
		if(isset($_GET['p']) && $_GET['p']!=='') {
			$page->id = $_GET['p'];
			$page->getModelManager()->load($page);
			$version = $page->findVersion();
			$outerTemplate = $version->getOuterContent()->template;
			$innerTemplate = $version->getInnerContent()->template;
		}
		else {
			$page->name = "Unknown";
			$page->title = "Page Not Found";
			$version = Model::create('PageVersion');
			$outerTemplate = $innerTemplate = 'unknown';
		}
		
		// Embed required javascripts
		$d = Config::get('ext.Scribble.docRoot');
		echo file_get_contents("{$d}/js/jquery-1.4.2.min.js");

		// Include javascript source
		include_once("{$d}/inline/scribble-inline.js.php");
		exit(0);
	}
}
?>